import fetch from "src/utils/fetch";
import API from "src/utils/api";
import notification from "src/utils/notification";


const Job = {
  state: {

    jobList:{
      list:[],
    },

  },
  mutations: {
    // job列表数据
    SetJobList(state,data){
      state.jobList.list=data.jobInfoList ? data.jobInfoList : [];
    },
  },
  actions: {

    // job 新增-编辑-删除
    doJobName: ({ state, commit }, params) => {

      let url='';

      if(params.cb){
        var cb=params.cb;
        delete params.cb;
      }

      if(params.type == 'add'){
        url=API.batch.jobAddInfo;
      }else if(params.type == 'edit'){
        url=API.batch.jobUpdateInfo;
      }else if(params.type == 'del'){
        url=API.batch.jobDeletedInfo;
      }else{
        return;
      }

      fetch({
        commit: commit,
        url: url,
        type: "post",
        data: params.data,
        showRegionLoading: true,
        success: (data)=>{
          notification.success('操作成功!');
          cb && cb();
          this.a.actions.getJobList({state, commit },{});
        },
      });
    },

    getJobList: ({ state, commit }, params) => {

      fetch({
        commit: commit,
        url: API.batch.jobList,
        type: "post",
        data: params,
        showRegionLoading: true,
        success: (data)=>{
          commit("SetJobList", data);
        },
      });
    },
  },
  getters: {

    jobList:(state, rootState)=>state.jobList,

  }
};

export default Job;
